<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :show="show" @click-show="show = !show" :fixed="true" :back="true" color="#fff" title="协商议事"></uni-navbar></view>

		<view class="filter-box" v-if="show">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="标题">
						<u-input v-model="discussTopicInfo.title" type="text" placeholder="请输入标题" />
					</u-form-item>

					<u-form-item class="form-item" label="议题来源">
						<u-input v-model="issueSource" type="select" :select-open="issueSourceShow" placeholder="请选择来源" @click="issueSourceShow = true" />
						<u-select v-model="issueSourceShow" :list="issueSourceList" @confirm="issueSourceConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="信息分类">
						<u-input v-model="classify" type="select" :select-open="classifyShow" placeholder="请选择分类" @click="classifyShow = true" />
						<u-select v-model="classifyShow" :list="classifyList" @confirm="classifyConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="开始时间">
						<date-time-picker placeholder="请选择开始时间" :defaultValue="startTime" :old="true" fields="day" @change="timeChange($event, 'startTime')"></date-time-picker>
					</u-form-item>
					<u-form-item class="form-item" label="结束时间">
						<date-time-picker placeholder="请选择结束时间" :defaultValue="endTime" :old="true" fields="day" @change="timeChange($event, 'endTime')"></date-time-picker>
					</u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</view>

		<view class="search-view">
			<u-search class="search-input" shape="square" bg-color="#fff" v-model="discussTopicInfo.title" :show-filter="true" @search="search" @custom="show = !show"></u-search>
		</view>
		<u-tabs class="tab-box" :list="tabsList" :current="tabsCurrent" @change="tabsChange"></u-tabs>

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_01" v-for="(item, index) of assemblyList" :key="item.id" @click="navTo(item)">
				<view class="info-title">{{ item.title }}</view>
				<view class="info-btm">
					<view class="btm-left clamp">
						<text class="left-name">{{ item.submitName }}</text>
						<text class="left-time">{{ item.createTime }}</text>
					</view>
					<view class="btm-right">
						<view class="right-type" :style="'color:' + colorMap[item.topicNode]">{{ statusMap[item.topicNode] }}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>
		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import dateTimePicker from '@/components/uni-datetime-picker';
import { mapState } from 'vuex';
export default {
	components: {
		dateTimePicker
	},
	data() {
		return {
			scrollTop: 0,
			show: false,
			tabsCurrent: 0,
			tabsList: [
				{
					name: '所有',
					value: 0
				},
				{
					name: '议题初审',
					value: 2
				},
				{
					name: '议题审定',
					value: 3
				},
				{
					name: '议题公示',
					value: 4
				},
				{
					name: '商前调研',
					value: 5
				},
				{
					name: '协商情况',
					value: 6
				},
				{
					name: '成果审核',
					value: 7
				},
				{
					name: '结果公示',
					value: 9
				},
				{
					name: '存档',
					value: 11
				}
			],
			statusMap: {
				0: '所有',
				1: '提交',
				2: '初审',
				3: '审定',
				4: '公示',
				5: '调研',
				6: '协商',
				7: '成果审核',
				8: '议题办理',
				9: '结果公示',
				10: '评议反馈',
				11: '存档',
				12: '草稿',
				13: '公示',
				14: '调研发布',
				15: '协商发布',
				20: '留存',
				30: '预审'
			},
			colorMap: {
				0: '#303133',
				1: '#0099ff',
				2: '#ff9900',
				3: '#19be6b',
				4: '#ff3333',
				5: '#909399',
				6: '#606266',
				7: '#b5bfff',
				8: '#fcbd71',
				9: '#71d5a1',
				10: '#fab6b6',
				11: '#c8c9cc',
				12: '#909399',
				13: '#78bbff',
				14: '#f29100',
				15: '#18b566',
				20: '#dd6161',
				30: '#82848a',
				108: '#f3f4f6',
				109: '#dcdfe6'
			},
			flag_new: '1',
			region: '',
			nodeStatus: 0,
			topicNodeSea: '0',
			title: '',

			issueSource: '',
			issueSourceShow: false,
			issueSourceList: [
				{
					value: '1',
					label: '党政点题'
				},
				{
					value: '2',
					label: '代表荐题'
				},
				{
					value: '4',
					label: '公开征集'
				}
			],

			classify: '',
			classifyShow: false,
			classifyList: [],

			startTime: '',
			endTime: '',
			assemblyList: [],

			KeyWord: '',
			discussTopicInfo: {
				classify: '',
				classifyDetails: '',
				issueSource: '',
				roomId: '',
				title: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		if (option && option.topic) {
			this.topicNodeSea = option.topic;
			this.tabsCurrent = parseInt(option.topic) - 1;
		}
		this.loadData();
		this.loadDict('sqmy_category', 'classifyList');
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		dateRangeSea: {
			get: function () {
				let time = this.startTime + ' - ' + this.endTime;
				if (this.startTime == '' || this.endTime == '') {
					return '';
				} else {
					return time;
				}
			},
			set: function (e) {
				this.startTime = '';
				this.endTime = '';
			}
		},
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.region = this.userInfo.sysUser.remark2;
				this.roleCodes = this.userInfo.roleCodes.join(',');

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.topicNodeSea == 0) {
				this.topicNodeSea = '';
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				dateRange: this.dateRangeSea,
				KeyWord: this.KeyWord,
				userId: this.userId,
				region: this.region,
				flag_new: this.flag_new,
				roleCodes: this.roleCodes,
				topicNodeSea: this.topicNodeSea,
				discussTopicInfo: this.discussTopicInfo
			};
			if (this.$roleCodes('xsys_meeting_room')) {
				data.flag_new = '0';
			}
			if (this.$roleCodes('xsys_info')) {
				data.flag_new = '0';
			}
			this.$request('/xieshangyishi/info/list', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.assemblyList = [];
				}
				try {
					this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
					this.pageNum = this.pageNum + 1;
					this.assemblyList = this.assemblyList.concat(res.data.records);
				} catch (e) {
					this.loading = 'nomore';
				}
				this.loaded = true;
				if (this.assemblyList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		loadDict(type, list) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				this[list] = [];
				res.data.forEach((item) => {
					this[list].push({
						value: item.dictValue,
						label: item.dictName
					});
				});
			});
		},
		timeChange({ date, dt }, idx) {
			this[idx] = date.year + '-' + date.month2 + '-' + date.day2;
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			this.type(this.tabsList[index].value);
		},
		classifyConfirm(e) {
			this.classify = e[0].label;
			this.discussTopicInfo.classify = e[0].value;
		},
		issueSourceConfirm(e) {
			this.issueSource = e[0].label;
			this.discussTopicInfo.issueSource = e[0].value;
		},
		filter() {
			if (this.startTime == '' && this.endTime != '') {
				this.$msg('请选择开始时间');
				return false;
			}
			if (this.startTime != '' && this.endTime == '') {
				this.$msg('请选择结束时间');
				return false;
			}
			let arr = this.startTime.split('-');
			let startTime = new Date(arr[0], arr[1], arr[2]).getTime();

			let arrs = this.endTime.split('-');
			let endTime = new Date(arrs[0], arrs[1], arrs[2]).getTime();

			if (startTime >= endTime) {
				this.$msg('开始时间应小于结束时间');
				return false;
			}

			this.show = false;
			this.discussTopicInfo.dateRangeSea = this.dateRangeSea;
			this.loadData('refresh');
		},
		resert() {
			this.show = false;
			this.discussTopicInfo.title = '';
			this.classify = '';
			this.discussTopicInfo.classify = '';
			this.issueSource = '';
			this.discussTopicInfo.issueSource = '';
			this.dateRangeSea = '';
			this.loadData('refresh');
		},
		search(e) {
			this.KeyWord = e;
			this.loadData('refresh');
		},
		type(e) {
			this.nodeStatus = e;
			this.topicNodeSea = e.toString();
			this.loadData('refresh');
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pagesA/assembly/detail?id=' + item.id
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}

.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
		border-bottom: 20rpx solid #f5f7fa;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
